home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / wstype / source / graph.c < prev    next >
C/C++ Source or Header  |  1991-10-18  |  7KB  |  343 lines

  1. /***   [graph.c]
  2. *
  3. *    グラフィック 関連        (C)ささがわ
  4. *
  5. *    For GNU C Compiler (GCC)   Version 1.39
  6. *
  7. ***/
  8.  
  9. #define EGB_WORK_DEFINED
  10. #include <graph.h>
  11. #include <jctype.h>
  12. #include <string.h>
  13. #include <dos.h>
  14. #include <mos.h>
  15. #include "others.h"
  16.  
  17. #define GRP_BUFSIZ    4096
  18.  
  19. char    EGB_work[1536];
  20. extern int    PAL_Black;
  21. extern int    PAL_Button;
  22. static int    EGB_actpage;
  23. static char    workpar[128];
  24. static char    work1[GRP_BUFSIZ];
  25. static char    *workptr;
  26.  
  27. extern void    _Pixelx(void *, int, const void *);
  28. extern void    _Pixelstr(void *, const char *, int);
  29. extern void    _Pixelstr2(void *, const char *, const void *, int);
  30. static void wb(char);
  31. static void ww(short);
  32. static void wd(long);
  33.  
  34. void EGB_int(void) {
  35.     EGB_init(EGB_work, 1536);
  36.     EGB_actpage = 0;
  37. }
  38.  
  39. void EGB_actPage(int p) {
  40.     EGB_writePage(EGB_work, p);
  41.     EGB_actpage = p;
  42. }
  43.  
  44. int EGB_readactPage(void) {
  45.     return EGB_actpage;
  46. }
  47.  
  48. void EGB_cls(int c) {
  49.     EGB_color(EGB_work, EGB_COL_BACK, c);
  50.     EGB_clearScreen(EGB_work);
  51. }
  52.  
  53. void EGB_box(int x1, int y1, int x2, int y2, int c) {
  54.     EGB_paintMode(EGB_work, 0x002);
  55.     EGB_color(EGB_work, EGB_COL_FORE, c);
  56.     workptr = workpar;
  57.     ww(x1);
  58.     ww(y1);
  59.     ww(x2);
  60.     ww(y2);
  61.     EGB_rectangle(EGB_work, workpar);
  62. }
  63.  
  64. void EGB_boxf(int x1, int y1, int x2, int y2, int c1, int c2) {
  65.     EGB_paintMode(EGB_work, c1 != c2 ? 0x022 : 0x020);
  66.     EGB_color(EGB_work, EGB_COL_FORE, c1);
  67.     EGB_color(EGB_work, EGB_COL_PAINT, c2);
  68.     workptr = workpar;
  69.     ww(x1);
  70.     ww(y1);
  71.     ww(x2);
  72.     ww(y2);
  73.     EGB_rectangle(EGB_work, workpar);
  74. }
  75.  
  76. void EGB_pal(int n, int g, int r, int b, int syn) {
  77.     workptr = workpar;
  78.     wd(1);
  79.     wd(n);
  80.     wb(b);
  81.     wb(r);
  82.     wb(g);
  83.     wb(0);
  84.     EGB_palette(EGB_work, syn, workpar);
  85. }
  86.  
  87. void EGB_str(const char *str, int x, int y, int c) {
  88.     EGB_paintMode(EGB_work, 0x002);
  89.     EGB_color(EGB_work, EGB_COL_FORE, c);
  90.     workptr = workpar;
  91.     ww(x);
  92.     ww(y);
  93.     ww(strlen(str));
  94.     strcpy(workptr, str);
  95.     EGB_sjisString(EGB_work, workpar);
  96. }
  97.  
  98. void EGB_str2(const char *str, int x, int y, int c) {
  99.     int        i, l, l1, l2, xp;
  100.     const char    *strp;
  101.     
  102.     if ((l = strlen(str)) == 0)
  103.         return;
  104.     l1 = GRP_BUFSIZ / 16;
  105.     l2 = (l + l1 - 1) / l1 - 1;
  106.     strp = str;
  107.     xp = x;
  108.     for (i = 0; i < l2; i++) {
  109.         int        a;
  110.         
  111.         _Pixelstr(work1, strp, a = strLE(strp, l1));
  112.         EGB_putC(1, work1, xp, y - 15, xp + a * 8 - 1, y, c);
  113.         strp += a;
  114.         xp += a * 8;
  115.     }
  116.     _Pixelstr(work1, strp, l - (strp - str));
  117.     EGB_putC(1, work1, xp, y - 15, xp + (l - (strp - str)) * 8 - 1, y, c);
  118. }
  119.  
  120. void EGB_str3(const char *str, int x, int y, int c1, int c2) {
  121.     int        i, l, l1, l2, xp;
  122.     const char    *strp;
  123.     static int    cc1 = -1, cc2 = -1;
  124.     static unsigned char    table[1024];
  125.     
  126.     if (cc1 != c1 || cc2 != c2) {
  127.         int        i, ii;
  128.         unsigned    d;
  129.         
  130.         cc1 = c1;
  131.         cc2 = c2;
  132.         for (d = 0, ii = 0; ii < 1024; ii += 4) {
  133.             unsigned long    b;
  134.             
  135.             for (b = 0, i = 0; i < 8; i++) {
  136.                 if (d >> i & 1)
  137.                     b += cc1 << (7 - i) * 4;
  138.                 else
  139.                     b += cc2 << (7 - i) * 4;
  140.             }
  141.             for (i = 0; i < 4; i++)
  142.                 *(table + ii + i) = *((unsigned char *)(&b) + i);
  143.             d++;
  144.         }
  145.     }
  146.     
  147.     if ((l = strlen(str)) == 0)
  148.         return;
  149.     l1 = GRP_BUFSIZ / 64;
  150.     l2 = (l + l1 - 1) / l1 - 1;
  151.     strp = str;
  152.     xp = x;
  153.     for (i = 0; i < l2; i++) {
  154.         int        a;
  155.         
  156.         _Pixelstr2(work1, strp, table, a = strLE(strp, l1));
  157.         EGB_put(1, work1, xp, y - 15, xp + a * 8 - 1, y);
  158.         strp += a;
  159.         xp += a * 8;
  160.     }
  161.     _Pixelstr2(work1, strp, table, l - (strp - str));
  162.     EGB_put(1, work1, xp, y - 15, xp + (l - (strp - str)) * 8 - 1, y);
  163. }
  164.  
  165. void EGB_pointset(int x, int y, int c) {
  166.     EGB_paintMode(EGB_work, 0x002);
  167.     EGB_color(EGB_work, EGB_COL_FORE, c);
  168.     workptr = workpar;
  169.     ww(1);
  170.     ww(x);
  171.     ww(y);
  172.     EGB_pset(EGB_work, workpar);
  173. }
  174.  
  175. void EGB_get(void *buf, int x1, int y1, int x2, int y2) {
  176.     struct SREGS    sregs;
  177.     
  178.     workptr = workpar;
  179.     wd((long)buf);
  180.     segread(&sregs);
  181.     ww(sregs.ds);
  182.     ww(x1);
  183.     ww(y1);
  184.     ww(x2);
  185.     ww(y2);
  186.     EGB_getBlock(EGB_work, workpar);
  187. }
  188.  
  189. void EGB_put(int clip, const void *buf, int x1, int y1, int x2, int y2) {
  190.     struct SREGS    sregs;
  191.     
  192.     workptr = workpar;
  193.     wd((long)buf);
  194.     segread(&sregs);
  195.     ww(sregs.ds);
  196.     ww(x1);
  197.     ww(y1);
  198.     ww(x2);
  199.     ww(y2);
  200.     EGB_putBlock(EGB_work, clip, workpar);
  201. }
  202.  
  203. void EGB_putC(int clip, const void *buf, int x1, int y1, int x2, int y2, int c) {
  204.     struct SREGS    sregs;
  205.     
  206.     EGB_paintMode(EGB_work, 0x002);
  207.     EGB_color(EGB_work, EGB_COL_FORE, c);
  208.     workptr = workpar;
  209.     wd((long)buf);
  210.     segread(&sregs);
  211.     ww(sregs.ds);
  212.     ww(x1);
  213.     ww(y1);
  214.     ww(x2);
  215.     ww(y2);
  216.     EGB_putBlockColor(EGB_work, clip, workpar);
  217. }
  218.  
  219. void EGB_line(int x1, int y1, int x2, int y2, int c) {
  220.     EGB_paintMode(EGB_work, 0x002);
  221.     EGB_color(EGB_work, EGB_COL_FORE, c);
  222.     workptr = workpar;
  223.     ww(2);
  224.     ww(x1);
  225.     ww(y1);
  226.     ww(x2);
  227.     ww(y2);
  228.     EGB_unConnect(EGB_work, workpar);
  229. }
  230.  
  231. void EGB_rev(int c, int x1, int y1, int x2, int y2) {
  232.     int        i, l1, l2;
  233.     static char    init = 1;
  234.     static unsigned char    table[256];
  235.     
  236.     if (init) {
  237.         int        x, y;
  238.         char    table2[16];
  239.         
  240.         for (i = 0; i < 16; table2[i++] = -1);
  241.         table2[PAL_Black] = 15;
  242.         table2[15] = PAL_Black;
  243.         table2[PAL_Button] = PAL_Button;
  244.         table2[0] = 0;
  245.         table2[7] = 8;
  246.         table2[8] = 7;
  247.         
  248.         for (i = 0; i < 16; i++) {
  249.             int        ii;
  250.             
  251.             if (table2[i] != -1)
  252.                 continue;
  253.             
  254.             ii = i;
  255.             do {
  256.                 if (++ii >= 16)
  257.                     ii -= 16;
  258.             } while (table2[ii] != -1);
  259.             table2[i] = ii;
  260.             table2[ii] = i;
  261.         }
  262.         
  263.         for (y = 0; y < 16; y++) {
  264.             for (x = 0; x < 16; x++)
  265.                 table[(y << 4) + x] = (table2[y] << 4) + table2[x];
  266.         }
  267.         
  268.         init = 0;
  269.     }
  270.     
  271.     if (c)    MOS_disp(0);
  272.     
  273.     l1 = GRP_BUFSIZ / ((x2 - x1 + 8) / 8 * 4);
  274.     l2 = (y2 - y1 + l1) / l1;
  275.     for (i = 0; i < l2 - 1; i++) {
  276.         EGB_get(work1, x1, y1 + i * l1, x2, y1 + (i + 1) * l1 - 1);
  277.         _Pixelx(work1, (x2 - x1 + 8) / 8 * 4 * l1, table);
  278.         EGB_put(1, work1, x1, y1 + i * l1, x2, y1 + (i + 1) * l1 - 1);
  279.     }
  280.     EGB_get(work1, x1, y1 + i * l1, x2, y2);
  281.     _Pixelx(work1, (x2 - x1 + 8) / 8 * 4 * ((y2 - y1 + 1) - l1 * (l2 - 1)), table);
  282.     EGB_put(1, work1, x1, y1 + i * l1, x2, y2);
  283.     
  284.     if (c)    MOS_disp(1);
  285. }
  286.  
  287. void EGB_scrl(int m, int x1, int y1, int x2, int y2, int wx, int wy) {
  288.     workptr = workpar;
  289.     ww(x1);
  290.     ww(y1);
  291.     ww(x2);
  292.     ww(y2);
  293.     EGB_partScroll(EGB_work, m, wx, wy, workpar);
  294. }
  295.  
  296. void EGB_mycopy(int p1, int x1, int y1, int x2, int y2, int p2, int x, int y) {
  297.     int        i, l1, l2, p;
  298.     
  299.     p = EGB_actpage;
  300.     l1 = GRP_BUFSIZ / ((x2 - x1 + 8) / 8 * 4);
  301.     l2 = (y2 - y1 + l1) / l1;
  302.     for (i = 0; i < l2 - 1; i++) {
  303.         EGB_actPage(p1);
  304.         EGB_get(work1, x1, y1 + i * l1, x2, y1 + (i + 1) * l1 - 1);
  305.         EGB_actPage(p2);
  306.         EGB_put(0, work1, x, y + i * l1, x + (x2 - x1), y + (i + 1) * l1 - 1);
  307.     }
  308.     EGB_actPage(p1);
  309.     EGB_get(work1, x1, y1 + i * l1, x2, y2);
  310.     EGB_actPage(p2);
  311.     EGB_put(0, work1, x, y + i * l1, x + (x2 - x1), y + y2 - y1);
  312.     EGB_actPage(p);
  313. }
  314.  
  315. void EGB_view(int x1, int y1, int x2, int y2) {
  316.     workptr = workpar;
  317.     ww(x1);
  318.     ww(y1);
  319.     ww(x2);
  320.     ww(y2);
  321.     EGB_viewport(EGB_work, workpar);
  322. }
  323.  
  324. void EGB_Hscrl(int a, int b) {
  325.     EGB_displayStart(EGB_work, EGB_DSP_SHIFT, a, b);
  326. }
  327.  
  328. static void wb(char b) {
  329.     *(workptr++) = b;
  330. }
  331.  
  332. static void ww(short w) {
  333.     *(workptr++) = *((char *)&w);
  334.     *(workptr++) = *((char *)&w + 1);
  335. }
  336.  
  337. static void wd(long d) {
  338.     *(workptr++) = *((char *)&d);
  339.     *(workptr++) = *((char *)&d + 1);
  340.     *(workptr++) = *((char *)&d + 2);
  341.     *(workptr++) = *((char *)&d + 3);
  342. }
  343.